 <?php

 	// Functions and Class
	require_once '../framework/header.inc.php';
	
	define('SID',$_GET['sid']);
	define('PAGE',$_GET['page']);
	
	// Set default page structure
	$extended['left'] = "navigation:sections,accordions:topbooks:favorites:pending";
	$extended['content:clearer'] = "books,bottom";
	$page->constructor("default",$extended);
	$page->url['sid'] = SID;
	$page->leaf(PAGE,"SELECT book_id FROM book WHERE book_section_id = '".SID."' AND book_access != '0' AND book_approve = '0'");

	// Set page scripts
	$script['jquery'] = array("jquery.js", "jquery.accordion.js");
	$extended = $page->loadFile("scripts/jquery/jquery.inc.js");
	$page->setScript($script,$extended);

	// Get all books for this SID
	$sql = mysql_query("SELECT book_id, book_author_id, book_volume, book_title, book_counter, book_access
						FROM book WHERE book_section_id = ".SID." AND book_access != '0' AND book_approve = '0'
						ORDER BY book_post_date DESC LIMIT ".$page->leaf['offset'].",".$page->default['rowsPerPage']."");

	
	if (mysql_num_rows($sql) > 0) {

		while ($row = mysql_fetch_assoc($sql)) {

			$row['book_author'] = implode(mysql_fetch_assoc(mysql_query("SELECT author_name FROM author WHERE author_id=".$row['book_author_id']."")));
			$row['book_comments'] = mysql_num_rows(mysql_query("SELECT comment_id FROM comment WHERE comment_category_id = '0' AND comment_book_id='".$row['book_id']."'"));
			$row['book_bookmarks'] = mysql_num_rows(mysql_query("SELECT bookmark_id FROM bookmark WHERE bookmark_book_id='".$row['book_id']."'"));
			$row['book_stars'] = stars($row['book_id']);
			$row['book_access'] = $options['access'][$row['book_access']];
			$row['book_counter'] = $row['book_counter'];
			$books[] = $row;
		}
	}
	

	// Page render
	$page->render("CATEGORY",$page->category());
	$page->render("SECTIONS",$page->sections(SID));
	$page->render("FOOTMENU",$page->navigation("footmenu",null));
	$page->render("FAVORITES",bookmarks(UID, SID));
	$page->render("TOPBOOKS",topbooks(SID));
	$page->render("PENDING",pending());
	$page->render("BOOKS",$books);
	$page->render("BOTTOM",$page->leaf);
	$page->show();

?>